package com.laf.manage.controller.admin;


import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.laf.common.utils.SecurityUtils;
import com.laf.common.utils.poi.ExcelUtil;
import com.laf.manage.domain.po.Point;
import com.laf.manage.domain.vo.PointVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.laf.common.annotation.Log;
import com.laf.common.core.controller.BaseController;
import com.laf.common.core.domain.AjaxResult;
import com.laf.common.enums.BusinessType;

import com.laf.manage.service.IPointService;

import com.laf.common.core.page.TableDataInfo;

/**
 * 点位管理Controller
 *
 * @author zian
 * @date 2024-10-30
 */
@Api(tags="点位管理管理")
@RestController("adminPointController")
@RequestMapping("/admin/point")
public class PointController extends BaseController
{
    @Autowired
    private IPointService pointService;

    /**
     * 查询点位管理列表
     */
    @ApiOperation("查询点位管理列表")
    @PreAuthorize("@ss.hasPermi('manage:point:list')")
    @GetMapping("/list")
    public TableDataInfo list(Point point)
    {
        startPage();
        List<PointVO> list = pointService.selectPointList(point);
        return getDataTable(list);
    }

    /**
     * 导出点位管理列表
     */
/*
    @ApiOperation("导出点位管理列表")
    @PreAuthorize("@ss.hasPermi('manage:point:export')")
    @Log(title = "点位管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Point point)
    {
        List<Point> list = pointService.selectPointList(point);
        ExcelUtil<Point> util = new ExcelUtil<Point>(Point.class);
        util.exportExcel(response, list, "点位管理数据");
    }
*/

    /**
     * 获取点位管理详细信息
     */
    @ApiOperation("获取点位管理详细信息")
    @PreAuthorize("@ss.hasPermi('manage:point:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pointService.getById(id));
    }

    /**
     * 新增点位管理
     */
    @ApiOperation("新增点位管理")
    @PreAuthorize("@ss.hasPermi('manage:point:add')")
    @Log(title = "点位管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Point point)
    {
        Long userId = SecurityUtils.getUserId();
        point.setCreateBy(userId.toString());
        point.setUpdateBy(userId.toString());
        LocalDateTime now = LocalDateTime.now();
        point.setCreateTime(now);
        point.setUpdateTime(now);
        return toAjax(pointService.save(point));
    }

    /**
     * 修改点位管理
     */
    @ApiOperation("修改点位管理")
    @PreAuthorize("@ss.hasPermi('manage:point:edit')")
    @Log(title = "点位管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Point point)
    {
        Long userId = SecurityUtils.getUserId();
        point.setUpdateBy(userId.toString());
        return toAjax(pointService.updateById(point));
    }

    /**
     * 删除点位管理
     */
    @ApiOperation("删除点位管理")
    @PreAuthorize("@ss.hasPermi('manage:point:remove')")
    @Log(title = "点位管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {

        return toAjax(pointService.removeByIds(Arrays.asList(ids)));
    }
}
